import { Fragment } from '@/components/Fragment';
import { Menu, MenuItem, View } from '@aws-amplify/ui-react';
import { MenuDemo } from './demo';
import {
BasicExample,
ControlledExample,
MenuAlignExample,
MenuExample,
MenuItemsExample,
SizeExample,
StylePropsExample,
MenuThemeExample,
} from './examples/';
import { Example, ExampleCode } from '@/components/Example';
import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay';
import ThemeExample from '@/components/ThemeExample.mdx';
## Demo
## Usage
Import the `Menu` and `MenuItem` components. Note that the Menu component is rendered in a React Portal, so you can set the Menu button's width from its outer container.
```tsx file=./examples/basicExample.tsx
````
### Menu items
Use the `MenuItem` component to configure Menu options. The example below demonstrates how to add interactivity to the `MenuItem`'s via the `onClick` handler, as well as how to use the `Divider` component and `isDisabled` prop.
```tsx file=./examples/menuItemsExample.tsx
````
### Customize Menu button
The default Menu button can be customized by importing the `MenuButton` component and passing it to the `Menu`'s `trigger` prop. `MenuButton` can take all the same props as [Button](./button).
```tsx file=./examples/menuExample.tsx
````
### Menu alignment
To control the alignment of the Menu with the Menu button, use the `menuAlign` prop. Available options are `start` (default), `center`, and `end`.
```tsx file=./examples/menuAlignExample.tsx
````
### Size
Control the size of the Menu button and items using the `size` prop. Available options are `small`, none (default), and `large`.
```tsx file=./examples/sizeExample.tsx
````
### Controlled Menu
Create a controlled `Menu` using the `isOpen` and `onOpenChange` props.
```tsx file=./examples/controlledExample.tsx
````
## CSS Styling
```tsx file=./examples/MenuThemeExample.tsx
```
### Target classes
### Global styling
To override styling on all Menus, you can set the Amplify CSS variables with the built-in classes.
```css
/* styles.css */
.amplify-menu-content {
--amplify-components-button-color: var(--amplify-colors-brand-secondary-90);
}
.amplify-menu-trigger {
--amplify-components-button-border-color: var(
--amplify-colors-brand-secondary-90
);
--amplify-components-button-color: var(--amplify-colors-brand-secondary-90);
}
```
```jsx
import { Menu, MenuItem } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
import './styles.css';
export const GlobalStylingExample = () => (
);
```
### Local styling
To override styling on a specific Menu, you can use (in order of increasing specificity): a class selector, data attributes, or style props.
_Using a class selector:_
Note: The `classname` prop is applied to the Menu dropdown content. Use the `triggerClassName` prop to apply a class to the menu trigger button.
```css
/* styles.css */
.my-menu-trigger.amplify-menu-trigger {
border-color: var(--amplify-colors-brand-secondary-90);
color: var(--amplify-colors-brand-secondary-90);
}
.my-menu-content .amplify-menu-content__item {
color: var(--amplify-colors-brand-secondary-90);
}
.my-menu-content .amplify-menu-content__item:hover {
background-color: var(--amplify-colors-brand-secondary-90);
}
```
```jsx
import { Menu, MenuItem } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
import './styles.css';
export const ClassNameExample = () => (
);
```
_Using data attributes:_
```css
/* styles.css */
.amplify-menu-content__item[data-size='large'] {
font-size: var(--amplify-font-sizes-xxxxl);
}
```
```jsx
import { Menu, MenuItem } from '@aws-amplify/ui-react';
import '@aws-amplify/ui-react/styles.css';
import './styles.css';
export const DataAttributesExample = () => (
);
```
_Using style props:_
```tsx file=./examples/stylePropsExample.tsx
```